package main

import (
	"fmt"
	"math/rand"
	"sync"
	"time"
)

type Worker struct {
	ID         int
	TaskChan   <-chan Task
	ResultChan chan<- string
}

func (w *Worker) Start(wg *sync.WaitGroup) {

	defer wg.Done()
	for task := range w.TaskChan {
		// 模拟处理任务
		processTime := time.Duration(rand.Intn(1000)+500) * time.Millisecond
		time.Sleep(processTime)
		result := fmt.Sprintf("Worker %d 完成任务 %d（耗时 %v）", w.ID, task.ID, processTime)
		w.ResultChan <- result
	}
}
